package org.gd136.ce.game;

import org.gd136.ce.manager.RM;
import org.gd136.ce.stage.LogoLayer;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.badlogic.gdx.utils.viewport.Viewport;

public class AppGame implements ApplicationListener {

	Viewport viewport = new ExtendViewport(1280, 720);
	Stage stage;
	BitmapFont debugFont;
	Label debugLabel;

	@Override
	public void create() {
		GS.width = Gdx.graphics.getWidth();
		GS.height = Gdx.graphics.getHeight();
		// /
		Gdx.gl.glClearColor(0, 0, 0, 0);

		RM.asset();

		Gdx.graphics.setTitle("-CodeEmotion-");
		// /////////
		stage = new Stage(viewport);
		Gdx.input.setInputProcessor(stage);
		GS.stage = stage;
		// //////////
		RM.parameter().incremental = true;
		RM.parameter().borderWidth = 1;
		RM.parameter().borderColor = Color.WHITE;
		RM.parameter().color = Color.RED;
		RM.parameter().size = 24;
		debugFont = RM.generateFont();
		debugLabel = new Label("FPS:0123456789", new LabelStyle(debugFont,
				Color.WHITE));
		debugLabel.setAlignment(Align.bottomLeft);
		debugLabel.setPosition(20, 20);

		stage.addActor(new LogoLayer());

		stage.addActor(debugLabel);
	}

	@Override
	public void resize(int width, int height) {
		// can't resize.
	}

	@Override
	public void render() {
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

		debugLabel.setText(String.format("FPS:%d",
				Gdx.graphics.getFramesPerSecond()));
		stage.addActor(debugLabel);

		stage.act();
		stage.draw();
	}

	@Override
	public void pause() {

	}

	@Override
	public void resume() {

	}

	@Override
	public void dispose() {
		RM.dispose();
		debugFont.dispose();
		stage.dispose();
	}

}
